<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>time format</title>
</head>
<body>


</body>
</html>

<script>

  function formatTime(date) {
    console.log(date)
    var Y = date.getFullYear() + '/';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '/';
    var D = date.getDate() + ' ';
    if (D < 10) D = '0' + D;
    var h = date.getHours() + ':';
    if (h < 10) h = '0' + h;
    var m = date.getMinutes() + ':';
    if(m < 10){
      m = '0' + m;
      console.log(m)
    }
    var s = date.getSeconds();
    if (s < 10) s = '0' + s;
    return Y + M + D + h + m + s;
    // console.log(Y + M + D + h + m + s)
    // 输出结果：2018-12-24 16:01:00
  }

  console.log(formatTime())
</script>